package com.qf.demo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.demo.dao.CartDao;
import com.qf.demo.dao.ProductDao;
import com.qf.demo.entity.Cart;
import com.qf.demo.entity.Product;
import com.qf.demo.entity.bcata;
import com.qf.demo.service.CartService;
import com.qf.demo.service.goodsService;
import com.qf.demo.vo.goodDetail;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;

@Service
public class CartServiceImpl extends ServiceImpl<CartDao, Cart> implements CartService {

    @Autowired
    private CartDao cartDao;

    @Autowired
    private ProductDao pp;


    @Override
    public void upDateOrInsert(Integer uid,Integer pid) {
        Cart cart=cartDao.selectC(uid,pid);
        System.out.println(cart);
        if(Objects.isNull(cart)){

            Product product = pp.selectById(pid);
            BigDecimal price=product.getPprice();
            cartDao.insertCart(uid,pid,price);
            return;
        }


        cart.setCcount(cart.getProduct().getPprice().add(cart.getCcount()));
        cart.setCnum(cart.getCnum()+1);
        cartDao.updateCart(cart);




    }
}
